
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>多维数组的实现</title>
</head>
<body>
	<h1>多维数组的实现</h1>
	<!-- document设定name值读取 -->
	<form id="form1" name="form1">
		<input type="text" id="Num1" name="Num1" size="15" value="行数">
		<input type="text" id="Num2" name="Num2" size="15" value="列数">
		<input type="button" value="列数组" onclick="NumSubmit();">
		<script type="text/javascript">
			function NumSubmit() {
				InputNum1 = document.form1.Num1.value;
				InputNum2 = document.form1.Num2.value;
				
				if(isNaN(InputNum1) || isNaN(InputNum2)) {
					alert("");
				} else {
					if(InputNum1=="" || InputNum2=="") {
						alert();
					} else {
						showMultiArr(InputNum1, InputNum2);
					}
				}
			}
			
			function showMultiArr(h, w) {
				var i, k, h, w;
				var myArr = [];
				var subArr = [];
				
				for(i=0; i<h; i++) {
					for(k=0; k<w; k++) {
						subArr[k] = k;
					}
					myArr[i] = subArr;
				}
				
				document.write("<title>多维数组的实现</title>");
				document.write(h + "行" + w + "列的二维数组<hr>");
				for(var m=0; m<myArr.length; m++) {
					for(var n=0; n<subArr.length; n++) {
						document.write("myArr[" + m + "][" + n + "]=" + myArr[m][n] + "; ");
					}
					document.write("<br>");
				}
			}
		
		</script>	
	</form>
</body>
</html>